package org.nokatag.Connection;

import java.sql.Connection;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.Concest;
import org.nokatag.system.ServletNokaContext;
import org.nokatag.system.SpringObjectFactory;

public class SpringIbatisSessionFactory extends  SpringObjectFactory implements DBConnectionInterface{

	public Connection getConnection() {
		//ApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletNokaContext.getServletContext());
		SqlSessionFactory sqlSessionFactory = (SqlSessionFactory)bulidBean(Concest.DB_SPRING_SESSION_FACTORY);//ac.getBean(Concest.DB_SPRING_SESSION_FACTORY);
		SqlSession isession = sqlSessionFactory.openSession();
		ServletNokaContext.setIbatisSession(isession);
		return isession.getConnection();
	}

	public void closeConnection(Connection con) {
		try{
			if(null!=con){
				try{con.close();}catch(Exception se){BugInfoWrint.Print(se);}
				ServletNokaContext.getIbatisSession().close();
			}
		}catch(Exception se){
			
		}
	}

}

